﻿#include <QApplication>
#include "../Network/NetClient.h"
#include "Debug.h"
#include "LoginWidget.h"
#include "MainWidget.h"
#include "Model/DataCenter.h"

void msgHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
    static FILE* output   = fopen("log.txt", "a");
    QByteArray   localMsg = msg.toUtf8();
    fprintf(output, "%s\n",
            localMsg.constData());
    fflush(output);
}

int main(int argc, char* argv[])
{
    QApplication a(argc, argv);
    int          res = 0;
#if TEST_LOGIN
    LoginWidget* loginWidget = LoginWidget::get_instance();
    loginWidget->show();
    res = a.exec();
#elif TEST_NETWORK
    /*NetClient* net_client = new NetClient();
    net_client->ping();
    net_client->init_web_socket();*/
    model::DataCenter* data_center = model::DataCenter::get_instance();
    data_center->ping();
    data_center->init_socket();
    res = a.exec();  // 别忘了启动事件循环
#elif TEST_UI
    MainWidget* w = MainWidget::get_instance();
    w->show();
    res = a.exec();
#elif NORMAL_TEST
    qInstallMessageHandler(msgHandler);
    LoginWidget* loginWidget = LoginWidget::get_instance();
    loginWidget->show();
    res = a.exec();
#else
    LOG() << "Not Defined Test Mode";
#endif
    return res;
}
